package cn.tedu.charging.cost.controller;

import cn.tedu.charging.common.pojo.param.ProgressCostParam;
import cn.tedu.charging.common.pojo.vo.ProgressCostVO;
import cn.tedu.charging.common.protocol.JsonResult;
import cn.tedu.charging.cost.service.CostService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CostController {

    private static final Logger log = LoggerFactory.getLogger(CostController.class);

    @Autowired
    private CostService costService;

    @PostMapping("/cost/bill/calculate")
    public JsonResult<ProgressCostVO> calculateCost(@RequestBody ProgressCostParam cost){
        log.debug("service:{}",costService);

        long id = Thread.currentThread().getId();
        String name = Thread.currentThread().getName();
        long startTime = System.currentTimeMillis();
        log.debug("线程id:{},线程名称:{},开始时间:{}",id,name,startTime);
        log.debug("计算价格入参:{}",cost);
        ProgressCostVO vo = costService.calculateCost(cost);
        log.debug("计算价格入参:{},出参:{}",cost,vo);
        JsonResult ok = JsonResult.ok(vo);
        log.debug("线程id:{},线程名称:{},耗时:{}",id,name,System.currentTimeMillis() - startTime);
        return ok;
    }
}
